package com.yz.study.ref;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class GenericDemo {
    public <T> T getObject(Class<T>clazz) throws Exception{
        T t=clazz.newInstance();
        return t;
    }
    public static void main(String[] args)throws Exception{
        GenericDemo genericDemo=new GenericDemo();
        Product product = (Product) genericDemo.getObject(Class.forName("com.yz.study.ref.Product"));
        product.setId(11);
        product.setProductName("iphone 18pro max");
        System.out.println(product);

    }
}


@AllArgsConstructor
@NoArgsConstructor
@Data
class Product{
    private int id;
    private String productName;
}